import React from 'react'
import Test from '../components/router-nest/Test'
import { Route, Redirect } from 'react-router-dom'

export default function AuthRoute ({ children, component: Component, ...rest }) {
  return (
    <Route
      {...rest}
      render={props => {
        const token = localStorage.getItem('token')

        if (token) {
          return children ? children : <Component />
        } else {
          return (
            // 上述问题的解决办法1
            <Redirect to={`/login?redirect=${props.location.pathname}`} />
          )
        }
      }}
    />
  )
}
